<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProductSkuAttribute extends Model
{
    protected $fillable = [
        'product_id',
        'attribute_id',
        'attribute_value',
    ];

    public function parent()
    {
        return $this->belongsTo(Attribute::class, 'attribute_id');
    }

    public function scopeOptions($q)
    {
        $attrs = $q->get();

        $options = [];
        foreach ($attrs as $attr) {
            $options[] = [
                'id' => $attr->id,
                'text' => $attr->parent->name . ":" . $attr->attribute_value,
            ];
        }

        return $options;
    }
}
